package com.dwxt.sport.business.controller;

import com.dwxt.common.base.BaseResult;
import com.dwxt.sport.business.entity.AlarmHandle;
import com.dwxt.sport.business.entity.AlarmInfo;
import com.dwxt.sport.business.service.AlarmService;
import com.dwxt.sport.business.vo.alarm.InsertOrUpdateAlarmHandleVo;
import com.dwxt.sport.business.vo.alarm.InsertOrUpdateAlarmInfoVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 报警相关 Controller
 *
 * @author Kuang.JiaZhuo
 * @date 2020-08-03 15:15
 */
@RestController
@RequestMapping("/alarm")
@Api(tags={"报警相关接口"})
public class AlarmController {

    @Resource
    AlarmService alarmService;

    @ApiOperation(value = "新增或修改报警信息", notes = "新增或修改报警信息", response = Integer.class)
    @PostMapping("/back/insertOrUpdateAlarmInfo")
    public BaseResult insertOrUpdateAlarmInfo(InsertOrUpdateAlarmInfoVo insertOrUpdateVo){
        int result = this.alarmService.insertOrUpdateAlarmInfo(insertOrUpdateVo);
        return BaseResult.ok(result);
    }

//    @ApiOperation(value = "获取报警信息列表", notes = "按条件查询报警信息列表(带分页)", response = AlarmInfo.class)
//    @PostMapping("/back/selectAlarmInfoByCriteria")
//    public BaseResult selectAlarmInfoByCriteria(SelectAlarmInfoVo selectVo){
//        PageInfo<AlarmInfo> pageInfo = this.alarmService.selectAlarmInfoByCriteria(selectVo);
//        return BaseResult.ok(pageInfo);
//    }

    @ApiOperation(value = "获取报警信息列表", notes = "查询所有报警信息列表(带分页)", response = AlarmInfo.class)
    @PostMapping("/back/selectAlarmInfoByAll")
    public BaseResult selectAlarmInfoByAll(@ApiParam(value = "起始页") @RequestParam(required = false) Integer pageNum,
                                           @ApiParam(value = "页大小") @RequestParam(required = false) Integer pageSize){
        PageInfo<AlarmInfo> pageInfo = this.alarmService.selectAlarmInfoByPage(pageNum,pageSize);
        return BaseResult.ok(pageInfo);
    }

    @ApiOperation(value = "删除报警信息", notes = "根据ids批量删除报警信息", response= Integer.class)
    @PostMapping(value = "/back/deleteAlarmInfoByIds")
    public BaseResult deleteAlarmInfoByIds(@ApiParam(value = "要删除的id字符串,以英文逗号隔开", required = true) @RequestParam String ids){
        int result = this.alarmService.deleteAlarmInfoByIds(ids);
        return BaseResult.ok(result);
    }


    /******************************************************************  关联设备  ******************************************************************************/

    @ApiOperation(value = "新增 或 更新 报警处理", notes = "新增 或 更新 报警处理", response = Integer.class)
    @PostMapping("/back/insertOrUpdateAlarmHandle")
    public BaseResult insertOrUpdateAlarmHandle(InsertOrUpdateAlarmHandleVo insertOrUpdateVo){
        int result = this.alarmService.insertOrUpdateAlarmHandle(insertOrUpdateVo);
        return BaseResult.ok(result);
    }

    @ApiOperation(value = "删除报警处理", notes = "根据ids批量删除【报警处理】", response= Integer.class)
    @PostMapping(value = "/back/deleteAlarmHandleByIds")
    public BaseResult deleteAlarmHandleByIds(@ApiParam(value = "要删除的id字符串,以英文逗号隔开", required = true) @RequestParam String ids){
        int result = this.alarmService.deleteAlarmHandleByIds(ids);
        return BaseResult.ok(result);
    }

    @ApiOperation(value = "查询报警处理详情", notes = "根据报警信息的id查询报警处理的详情", response= AlarmHandle.class)
    @PostMapping(value = "/back/selectAlarmHandleByInfoId")
    public BaseResult selectAlarmHandleByInfoId(@ApiParam(value = "报警信息id", required = true) @RequestParam String id){
        String alarmInfoId = id;
        AlarmHandle alarmHandle = this.alarmService.selectAlarmHandleByInfoId(alarmInfoId);
        return BaseResult.ok(alarmHandle);
    }
}
